package filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Servlet Filter implementation class AdminFilter
 */
@WebFilter("/AdminFilter")
public class AdminFilter implements Filter {
    public AdminFilter() {
        // TODO Auto-generated constructor stub
    }

	public void destroy() {
		// TODO Auto-generated method stub
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
//        HttpServletResponse res = (HttpServletResponse) response;
//        req.getSession().getAttribute("root");
//        Cookie cookie = new Cookie("root","true");
//        System.out.println("1"+cookie);
//        res.addCookie(cookie);
        
        Cookie[] cookies = req.getCookies();
        System.out.println("2"+cookies);
        String co = cookies[0].getValue();
        System.out.println("3"+cookies[0].getValue());
//        req.getCookie().getValue();
		if(co.equals("true")) {
			System.out.println("成功");
			chain.doFilter(request, response);
		}else {
			System.out.println("失败");
		}
		
	}

	public void init(FilterConfig fConfig) throws ServletException {
		
		
		
	}

}
